package com.virtualparadigm.identity;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;

import com.virtualparadigm.compositor.ToStringStyleBuilder;

public class StringGUID implements GUID
{
	private static final long serialVersionUID = 1L;
	private String identifier;

	public StringGUID(String identifier)
	{
		this.identifier = identifier;
	}
	
	private String getIdentifier()
	{
		return this.identifier;
	}
	
	@Override
	public String getUniqueHash()
	{
		return this.getIdentifier();
	}

	//  ================================================================
	//  UTILITY METHODS
	//  ================================================================
	public int hashCode()
	{
		HashCodeBuilder builder = new HashCodeBuilder(17,31);
	    builder.append(this.getIdentifier());
	    return builder.toHashCode();		
	}
	public boolean equals(Object obj)
	{
		if (obj == null)
		{
			return false;
		}
		if (obj == this)
		{
			return true;
		}
		if (obj.getClass() != getClass())
		{
			return false;
		}
		StringGUID that = (StringGUID)obj;
		EqualsBuilder builder = new EqualsBuilder();
	    builder.append(this.getIdentifier(), that.getIdentifier());
		return builder.isEquals();
	}
	public String toString()
	{
//		return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
		return ReflectionToStringBuilder.toString(this, ToStringStyleBuilder.toStringStyle);
	}

}
